var SlowReminderList = [];

const slowRemiderParent = document.getElementById("miider");

/***
 * 慢提示
 */
export default function SlowReminder(text, time = 2000) {
    let divEle = document.createElement("div");
    if (divEle == null) return;

    divEle.className = "slowreminder";
    divEle.innerText = text;

    if (slowRemiderParent) {
        slowRemiderParent.appendChild(divEle);
    } else {
        document.body.appendChild(divEle);
    }

    // 历史节点向上移动
    for (let i = 0; i < SlowReminderList.length; i++) {
        const ele = SlowReminderList[i];
        ele.style.top = ele.offsetTop - 50 + "px";
    }

    SlowReminderList.push(divEle);

    let t = 10;
    let count = 0;
    let h = setInterval(() => {
        count += t;

        // 淡出
        if (count > time - 1000) {
            divEle.style.opacity = (time - count) / 1000;
        }

        if (count > time) {
            clearInterval(h);
            let idx = SlowReminderList.indexOf(divEle);
            if (idx != -1) {
                SlowReminderList.splice(idx, 1);
            }
            if (slowRemiderParent) {
                slowRemiderParent.removeChild(divEle);
            } else {
                document.body.removeChild(divEle);
            }
            // delete divEle;
            divEle = null;
        }
    }, t);
}
